package lee.study.controller;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import lee.study.service.TestService;
import lee.study.utils.ComputerInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.swing.text.html.FormSubmitEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

/**
 * Created by chenglong on 2017/11/5.
 */
@Controller
@RequestMapping("/test")
public class TestController {
    @Value("${tts.first.choice.1.sms.content:}")
    private String abc;

    @Autowired
    TestService testService;

    @RequestMapping("/async")
    @ResponseBody
    public String test() throws InterruptedException {
        String[] arrays = "1,1,1,1,1,1,1,1".split(",");
        testService.execAsyncMethod(arrays);
        return "执行结束！";
    }

    @RequestMapping("/getMac")
    @ResponseBody
    public String getMac() throws Exception {
        String mac = ComputerInfo.getMacAddress();
        System.out.println(new String(abc.getBytes("ISO8859-1"), "UTF-8"));
        File file = new File("G:\\新建文本文档 (4).txt");
        System.out.println(file.getAbsolutePath());
        return new String(abc.getBytes("ISO8859-1"), "UTF-8");
    }

    @RequestMapping("/getFileInfo")
    @ResponseBody
    public String getFileInfo(MultipartHttpServletRequest request) throws IOException {
        MultipartFile file =  request.getFile("file");
        System.out.println(file.getName());
        System.out.println(file.getOriginalFilename());
        InputStream inputStream = file.getInputStream();
        file.transferTo(new File("test.png"));
        return "success";
    }

    @RequestMapping("/sendMsg")
    @ResponseBody
    public Object sendMsg(){
        return null;
    }


}
